package com.driving.single.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 驾校自定义响应模型
 *
 * @author xsf
 * @version v1.0.0
 * @date 2019/12/15 0015
 * @see com.driving.single.common.entity
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DrivingResult implements Serializable {
    /**
     * 响应业务状态
     */
    private Integer status;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应中的数据
     */
    private Object data;


    private static final Integer OK_CODE = 200;
    private static final Integer ERROR_CODE = 500;

    public DrivingResult(Object data) {
        this.status = DrivingResult.OK_CODE;
        this.message = "OK";
        this.data = data;
    }

    public DrivingResult(Integer status, String message) {
        this.status = status;
        this.message = message;
        this.data = null;
    }

    public static DrivingResult ok() {
        return new DrivingResult(null);
    }

    public static DrivingResult ok(Object data) {
        return new DrivingResult(data);
    }

    public static DrivingResult error() {
        return new DrivingResult(DrivingResult.ERROR_CODE, null, null);
    }

    public static DrivingResult error(String msg) {
        return new DrivingResult(DrivingResult.ERROR_CODE, msg, null);
    }
}
